#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
根据鼠标点击，确认坐标
"""

__author__ = 'hubert'

import cv2 as cv

img_path = "/Users/hubert/Downloads/视频测试/longbiao.jpg"
image = cv.imread(img_path)


def on_EVENT_LBUTTONDOWN(event, x, y, flags, param):
    if event == cv.EVENT_LBUTTONDOWN:
        xy = "%d,%d" % (x, y)
        print(xy)
        cv.circle(image, (x, y), 5, (31, 23, 176), thickness=-1)
        # 可设置显示的坐标字体、大小、颜色
        cv.putText(image, xy, (x, y), cv.FONT_HERSHEY_SCRIPT_COMPLEX,
                    3.0, (0, 0, 255), thickness=1)
        cv.imshow("image", image)


if __name__ == '__main__':

    cv.namedWindow("image", cv.WINDOW_NORMAL)
    cv.setMouseCallback("image", on_EVENT_LBUTTONDOWN)
    cv.imshow("image", image)

    while(True):
        try:
            cv.waitKey(100)
        except Exception:
            cv.destroyWindow("image")
            break

    cv.waitKey(0)
    cv.destroyAllWindow()



